<template>
	<div class="demo">
		<input class="inp" type="text" v-model="msg" placeholder="请输入你的任务名称,按回车键确认" @keydown.enter="sendMsg"/>
		<ListComponent :list="list"></ListComponent>
		<div>
			<input type="checkbox" v-model="isCheck" @change="checkedAll" />
			<span>已完成{{checkedNumber}} / 全部{{count}}</span>
		</div>
	</div>
</template>

<script>
	import ListComponent from './components/List'
	export default {
		name:'App',
		data(){
			return {
				list:[
				],
				msg:'',
				isCheck:false,
			}
			
		},
		methods:{
			sendMsg(){
				if(this.msg !== ''){
					this.list.unshift({isChecked:false,name:this.msg,id:new Date().getTime()})
				}
				
			},
			checkedAll(){
				this.list.forEach(item => {
					item.isChecked = this.isCheck
				})
				
			}
		},
		computed:{
			count(){
				return this.list.length
			},
			checkedNumber(){
				let num = 0
				this.list.forEach(item => {
					if(item.isChecked === true){
						num++
					}
				})
				return num
			}
		},
		components:{ 
			ListComponent
		}
		
	}
</script>

<style scoped>
	/* .demo{
		width: 300px;
	} */
	.inp{
		width: 300px;
		padding: 5px;
		/* box-sizing: border-box; */
	}
</style>